package logic

import (
	"context"
	"github.com/jinzhu/copier"

	"my-zero-tiktok/apps/video/pb/pb"
	"my-zero-tiktok/apps/video/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetVideoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetVideoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVideoLogic {
	return &GetVideoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetVideo 获取视频
func (l *GetVideoLogic) GetVideo(in *pb.VideoIDRequest) (*pb.VideoItem, error) {
	video, err := l.svcCtx.VideoModel.FindOne(l.ctx, in.VideoId)
	if err != nil {
		return nil, err
	}
	var resp pb.VideoItem
	_ = copier.Copy(video, &resp)
	return &resp, nil
}
